package com.xiaozhi.boot.config;

import com.xiaozhi.boot.pojo.MyCar;
import com.xiaozhi.boot.pojo.Pet;
import com.xiaozhi.boot.pojo.User;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

//@Import({User.class, DBHelper.class})
@Configuration(proxyBeanMethods=true)
//没有tom名字的Bean时，MyConfig类的Bean才能生效
//@ConditionalOnBean(name="tom2")
//@ConditionalOnMissingBean(name="tom2")
@EnableConfigurationProperties(MyCar.class)
public class MyConfig {

    /**
     * Full:外部无论对配置类中的这个组件注册方法调用多少次获取的都是之前注册容器中的单实例对象
     * @return
     */
    @Bean //给容器中添加组件。以方法名作为组件的id。返回类型就是组件类型。返回的值，就是组件在容器中的实例
    //@ConditionalOnBean(name="tom")
    public User user01(){
        User zhangsan = new User("zhangsan", 18);
        //user组件依赖了Pet组件
        zhangsan.setPet(tomcatPet());
        return zhangsan;
    }
    @Bean("tom")
    public Pet tomcatPet(){
        return new Pet("tomcat");
    }
}
